﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using PlanetenGravity.ScreenSystem;
//GUI
using TomShane.Neoforce.Controls;
using TomShane.Neoforce.Importers;

namespace PlanetenGravity
{
    public class MainMenu : IGameScreen
    {
        Manager manager;
        Window mainmenu;
        public Game1 MainGame { get; set; }

        OptionsMenu optionen;

        public MainMenu(Game1 mainGame, GraphicsDeviceManager graphics)
        {
            MainGame = mainGame;
            manager = Game1.Manager;
            optionen = new OptionsMenu(MainGame, graphics);
        }

        public void Initialize(GraphicsDeviceManager graphics, ContentManager content)
        {
            manager.Initialize();
            mainmenu = new Window(manager);
            mainmenu.Init();
            mainmenu.Text = "Hauptmenue";
            mainmenu.Width = graphics.PreferredBackBufferWidth - 80;
            mainmenu.Height = graphics.PreferredBackBufferHeight - 200;
            mainmenu.Center();
            mainmenu.Visible = true;
			mainmenu.Alpha = 50;

            Button startButton = new Button(manager);
            startButton.Init();
            startButton.Text = "Spiel starten";
            startButton.Width = 200;
            startButton.Left = (mainmenu.ClientWidth / 2) - (startButton.Width / 2);
            startButton.Top = startButton.Height + 8;
            startButton.Anchor = Anchors.Bottom;
            startButton.Parent = mainmenu;
            startButton.Click += new MouseEventHandler(startButton_Click);

            Button endButton = new Button(manager);
            endButton.Init();
            endButton.Text = "Spiel beenden";
            endButton.Width = 200;
            endButton.Left = (mainmenu.ClientWidth / 2) - (endButton.Width / 2);
            endButton.Top = 16 + startButton.Height + endButton.Height;
            endButton.Anchor = Anchors.Bottom;
            endButton.Parent = mainmenu;
            endButton.Click += new MouseEventHandler(endButton_Click);

            Button optionsButton = new Button(manager);
            optionsButton.Init();
            optionsButton.Text = "Optionen";
            optionsButton.Width = 200;
            optionsButton.Left = (mainmenu.ClientWidth / 2) - (endButton.Width / 2);
            optionsButton.Top = 16 + startButton.Height + endButton.Height + 30;
            optionsButton.Anchor = Anchors.Bottom;
            optionsButton.Parent = mainmenu;
            optionsButton.Click += new MouseEventHandler(optionsButton_Click);

            manager.Add(mainmenu);
        }

        void optionsButton_Click(object sender, MouseEventArgs e)
        {
            MainGame.SwitchGameScreen(optionen);
        }
        void endButton_Click(object sender, MouseEventArgs e)
        {
            MainGame.Exit();
        }

        void startButton_Click(object sender, MouseEventArgs e)
        {
            MainGame.SwitchGameScreen(new Scene(MainGame));
        }

        public void UnloadContent()
        {
            mainmenu.Dispose();
            mainmenu = null;
        }

        public void Update(GameTime gameTime)
        {
            manager.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            manager.Draw(gameTime);
        }
    }
}